function tagcloud(options) {
  var selector = document.querySelector(options.selector);
  var items = selector.children;
  var radius = options.radius || 100;
  var fontsize = options.fontsize || 16;
  var mspeed = options.mspeed || "normal";
  var ispeed = options.ispeed || "normal";
  var direction = options.direction || 135;
  var keep = options.keep || false;

  var speedMap = {
    slow: 0.005,
    normal: 0.01,
    fast: 0.02,
  };

  var maxSpeed = speedMap[mspeed];
  var initSpeed = speedMap[ispeed];

  var angleX = 0;
  var angleY = 0;
  var speedX = initSpeed;
  var speedY = initSpeed;

  function positionItem(item, index) {
    var angle = (index / items.length) * Math.PI * 2;
    var x = Math.sin(angle) * radius;
    var y = Math.cos(angle) * radius;

    item.style.transform = "translate3d(" + x + "px, " + y + "px, 0)";
    item.style.fontSize = fontsize + "px";
  }

  function positionItems() {
    for (var i = 0; i < items.length; i++) {
      positionItem(items[i], i);
    }
  }

  function rotateX(angle) {
    selector.style.transform = "rotateX(" + angle + "deg)";
  }

  function rotateY(angle) {
    selector.style.transform = "rotateY(" + angle + "deg)";
  }

  function animate() {
    angleX += speedX;
    angleY += speedY;

    rotateX(angleX);
    rotateY(angleY);

    requestAnimationFrame(animate);
  }

  positionItems();
  animate();

  selector.addEventListener("mouseover", function () {
    speedX = maxSpeed;
    speedY = maxSpeed;
  });

  selector.addEventListener("mouseout", function () {
    if (!keep) {
      speedX = initSpeed;
      speedY = initSpeed;
    }
  });
}
